/*
 * Copyright (c) 2020, chao
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2020-08-20     chao         the first version
 */

#ifndef __XPT2046_CALIBARTION_H__
#define __XPT2046_CALIBARTION_H__

#include <stdint.h>

//logX = (phyX - phyCenterX)/kx + logCenterX;
//logY = (phyY - phyCenterY)/ky + logCenterY;

struct xpt_point {
    uint16_t x;
    uint16_t y;
};

struct xpt_cal {
    struct xpt_point log_point[4];  //逻辑测量点
    struct xpt_point phy_point[4];  //物理测量点
    struct xpt_point log_center;    //逻辑中心点,作为矫正基准点
    struct xpt_point phy_center;    //物理中心点
    float kx;                       //X方向缩放系数
    float ky;                       //Y方向缩放系数
};
typedef struct xpt_cal *xpt_cal_t;

int xpt2046_calibration_init(void);
uint16_t xpt_caculate_phy_x(uint16_t logX);
uint16_t xpt_caculate_phy_y(uint16_t logY);
uint16_t xpt_caculate_log_x(uint16_t phyX);
uint16_t xpt_caculate_log_y(uint16_t phyY);


#endif /* __XPT2046_CALIBARTION_H__ */


